<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>表白墙</title>
    <style>
        *{
            /* 消除浏览器默认样式 */
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        .container{
            margin: 30px auto;
            width: 600px ;
        }
        h1{
            text-align: center;
        }
        p{
            text-align: center;
            color: #666;
            margin: 20px;
        }
        .row{
            display: flex;
            justify-content: center;
            align-items: center;
            height: 40px;
        }
        span{
            width: 80px ;
        }
        .row input{
            width: 200px ;
            height: 30px ;
            border-radius: 5px ;
        }
        .row button{
            width: 280px ;
            height: 30px;
            color: white;
            background-color: orange;
            border: none;
            border-radius: 5px;
        }
        .row button:active{
            background-color: #666;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>表白墙</h1>
        <p>输入后点击提交，会将信息显示到表格中</p>
        <div class="row">
            <span>谁：</span>
            <input type="text">
        </div>
        <div class="row">
            <span>对谁：</span>
            <input type="text">
        </div>
        <div class="row">
            <span>说：</span>
            <input type="text">
        </div>
        <div class="row">
            <button>提交</button>
        </div>
    </div>
    <script>
        // 选中所有（querySelectorAll）的input标签和(querySelector)button标签
        let inputs = document.querySelectorAll('input');
        // let=String[]此时是一个数组
        let button = document.querySelector('button');
        let containerDiv = document.querySelector('.container')
        button.onclick = function(){
            // 点击时获取到三个输入框的文本内容
            let from = inputs[0].value;
            let to = inputs[1].value;
            let msg = inputs[2].value;
            if(from == ''||to==''||msg==''){
                return;
            }

        // 构造新的div
        let rowDiv = document.createElement('div');
        rowDiv.className = 'row';
        rowDiv.innerHTML = from +'对'+to +'说'+msg;
        // 把新建的div加到container的后面，
        containerDiv.appendChild(rowDiv);
        //清空之前输入框的内容方便后续输入
        for(let input of inputs){
            input .value='';
        }
    }
    </script>
</body>
</html>